//
// Created by guanyicheng on 2021/11/8.
//

#include <iostream>
#include <vector>
#include<algorithm>

using namespace std;

int main() {
    int n, temp, c;
    vector<int> v;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> temp;
        v.emplace_back(temp);
    }
    cin >> c;
    sort(v.begin(), v.end(), [=](int x, int y) {
        bool r = x > y;
        return c == 1 == r;
    });
    for(auto &o: v) {
        cout << o << " ";
    }
    cout << endl;
    return 0;
}